<?php
/**
 * Created by PhpStorm.
 * User: lee
 * Date: 2018/6/30
 * Time: 11:43
 */

namespace Biz\service;

use Biz\module\Classes\GoodsHistory as clsGoodsHistory;
use Doraemon\tools\ActionLog;
use Biz\cache\GoodsHistory as cGoodsHistory;
use Doraemon\tools\HhzClient;
use Biz\model\trade\OrderGoods as mOrderGoods;

/**
 * @deprecated
 */
class GoodsHistory
{

    const APP_SOURCE_NORMAL = 0; //
    const APP_SOURCE_THEPARAGRAPG = 1; //theparagraph

    public static function getNearGoodsBrowseList($uid, $nearDay = 7, $page = 1, $pageSize = 20, $appSource = self::APP_SOURCE_NORMAL)
    {

        return clsGoodsHistory::getNearGoodsBrowseList($uid . $appSource, $nearDay, $page, $pageSize);
    }

    public static function browseHistoryWithoutBought($uid, $appSource = self::APP_SOURCE_NORMAL)
    {
        $zsetKey = cGoodsHistory::getBrowseKey($uid . $appSource);
        $goodsIds = cGoodsHistory::zrevrange($zsetKey, 0, -1, 'withscores');
        $goodsIds = array_keys($goodsIds);
        $goodsIds = array_diff($goodsIds, array_keys(
            mOrderGoods::getUserBoughtGoodsIds($uid)
        ));
        return array_filter($goodsIds);
    }


    public static function addBrowseHistory($uid, $goodsId, $appSource = self::APP_SOURCE_NORMAL)
    {
        if($uid > 0){
            clsGoodsHistory::addBrowseHistory($uid . $appSource, $goodsId);

            clsGoodsHistory::remBrowseHistory($uid . $appSource);
        }
    }
}